﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class tbLoaiHang
    {
        private string malh;

        public string Malh
        {
            get { return malh; }
            set { malh = value; }
        }
        private string tenlh;

        public string Tenlh
        {
            get { return tenlh; }
            set { tenlh = value; }
        }
        private string mota;

        public string Mota
        {
            get { return mota; }
            set { mota = value; }
        }

        DBAccess db=new DBAccess();
        public DataTable dalDSLoaiHang()
        {
            string query = "HienThiLH";
            SqlParameter[] param = new SqlParameter[0];
            return db.GetDataTable(query, CommandType.StoredProcedure, param);
        }
        public bool dalThemLH()
        {
            bool res = false;
            string query = "ThemLH";
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@TenLH", Tenlh);
            param[1] = new SqlParameter("@Mota", Mota);
            res = db.DoExcecute(query, CommandType.StoredProcedure, param);
            return res;
        }
        public bool dalSuaLH()
        {
            bool res = false;
            string query = "SuaLH";
            SqlParameter[] param = new SqlParameter[3];
            param[0] = new SqlParameter("@MaLH", Malh);
            param[1] = new SqlParameter("@TenLH", Tenlh);
            param[2] = new SqlParameter("@MoTa", Mota);
            res = db.DoExcecute(query, CommandType.StoredProcedure, param);
            return res;
        }
        public bool dalXoaLH()
        {
            bool res2 = false;
            string query2 = "select * from MatHang where MaLH=@MaLH";
            SqlParameter[] param2 = new SqlParameter[1];
            param2[0] = new SqlParameter("@MaLH",Malh);
            res2 = db.DoExecuteReader(query2, CommandType.Text, param2);

            bool res = false;
            string query = "XoaLH";
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@MaLH", Malh);

            if (res2 == true)
                res = false;
            else
            {
                res = db.DoExcecute(query, CommandType.StoredProcedure, param);
                res = true;
            }
            return res;
        }
    }
}
